<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>proxy</title>
</head>
<body>
    <script type="module">
        // receiver会把原始对象的this指向proxy代理对象
        const target = {
            name: 'jack',
            age: 18,
            get car() {
                return this.color
            }
        }
        const targetProxy = new Proxy(target, {
            get(target, key, receiver) {
                console.log('get方法被触发了！')
                if (key === 'color') {
                    return '红色'
                }
                return Reflect.get(target, key, receiver)
            },
            set(target, key, value, receiver) {
                console.log('set方法被触发了！')
                return Reflect.set(target, key, value, receiver)
            },
            deleteProperty(target, key) {
                console.log('delete方法被触发了！')
                return Reflect.deleteProperty(target, key)
            }
        })
        console.log(targetProxy)
        console.log(targetProxy.car)
    </script>
</body>
</html>